<template>
  <a-drawer
    :title="title"
    :width="width"
    placement="right"
    :closable="false"
    @close="close"
    :visible="visible">
  
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">

        <a-form-item label="屏柜生产订单号	" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'cabProOrderNo', validatorRules.cabProOrderNo]" placeholder="请输入屏柜生产订单号	"></a-input>
        </a-form-item>
        <a-form-item label="屏柜编号	" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'cabNo', validatorRules.cabNo]" placeholder="请输入屏柜编号	"></a-input>
        </a-form-item>
        <a-form-item label="序号	" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'serialNo', validatorRules.serialNo]" placeholder="请输入序号	"></a-input>
        </a-form-item>
        <a-form-item label="装置生产订单号	" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'nuitProOrderNo', validatorRules.nuitProOrderNo]" placeholder="请输入装置生产订单号	"></a-input>
        </a-form-item>
        <a-form-item label="装置编号	" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'unitNo', validatorRules.unitNo]" placeholder="请输入装置编号	"></a-input>
        </a-form-item>
        <a-form-item label="工艺编号	" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'processRouteNo', validatorRules.processRouteNo]" placeholder="请输入工艺编号	"></a-input>
        </a-form-item>
        <a-form-item label="供应商编号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'supplierCode', validatorRules.supplierCode]" placeholder="请输入供应商编号"></a-input>
        </a-form-item>
        <a-form-item label="tid" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="[ 'tid', validatorRules.tid]" placeholder="请输入tid" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="1：未读（默认状态）
0：成功；" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'ioflag', validatorRules.ioflag]" placeholder="请输入1：未读（默认状态）
0：成功；"></a-input>
        </a-form-item>
        <a-form-item label="检测时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-date placeholder="请选择检测时间" v-decorator="[ 'updateTime', validatorRules.updateTime]" :trigger-change="true" style="width: 100%"/>
        </a-form-item>
        
      </a-form>
    </a-spin>
    <a-button type="primary" @click="handleOk">确定</a-button>
    <a-button type="primary" @click="handleCancel">取消</a-button>
  </a-drawer>
</template>

<script>

  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import JDate from '@/components/jeecg/JDate'  
  
  export default {
    name: "ZxjEip_2cPgzzglModal",
    components: { 
      JDate,
    },
    data () {
      return {
        form: this.$form.createForm(this),
        title:"操作",
        width:800,
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },

        confirmLoading: false,
        validatorRules:{
        cabProOrderNo:{rules: [{ required: true, message: '请输入屏柜生产订单号	!' }]},
        cabNo:{rules: [{ required: true, message: '请输入屏柜编号	!' }]},
        serialNo:{rules: [{ required: true, message: '请输入序号	!' }]},
        nuitProOrderNo:{rules: [{ required: true, message: '请输入装置生产订单号	!' }]},
        unitNo:{rules: [{ required: true, message: '请输入装置编号	!' }]},
        processRouteNo:{rules: [{ required: true, message: '请输入工艺编号	!' }]},
        supplierCode:{},
        tid:{rules: [{ required: true, message: '请输入tid!' }]},
        ioflag:{rules: [{ required: true, message: '请输入1：未读（默认状态）0：成功；!' }]},
        updateTime:{},
        },
        url: {
          add: "/ZxjEip2cPgzzgl/zxjEip_2cPgzzgl/add",
          edit: "/ZxjEip2cPgzzgl/zxjEip_2cPgzzgl/edit",
        }
     
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'cabProOrderNo','cabNo','serialNo','nuitProOrderNo','unitNo','processRouteNo','supplierCode','tid','ioflag','updateTime'))
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            console.log("表单提交数据",formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
          }
         
        })
      },
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'cabProOrderNo','cabNo','serialNo','nuitProOrderNo','unitNo','processRouteNo','supplierCode','tid','ioflag','updateTime'))
      }
      
    }
  }
</script>

<style lang="less" scoped>
/** Button按钮间距 */
  .ant-btn {
    margin-left: 30px;
    margin-bottom: 30px;
    float: right;
  }
</style>